//
//  MSMationURLController.m
//  觅尚
//
//  Created by No.8 on 2019/4/13.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSMationURLController.h"
#import <WebKit/WebKit.h>

@interface MSMationURLController ()<WKNavigationDelegate,UINavigationControllerDelegate,WKUIDelegate>
{
    CustomNavigationBar *naviagtionBar;
}
@end

@implementation MSMationURLController

- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self CreateNavigationBar];
    
    
    [self CreatView];
    
}

- (void)CreatView{
    WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
    
    config.preferences = [[WKPreferences alloc] init];
    
    config.preferences.minimumFontSize = 10;
    
    config.preferences.javaScriptEnabled = YES;
    
    config.preferences.javaScriptCanOpenWindowsAutomatically = NO;
    
    config.userContentController = [[WKUserContentController alloc] init];
    
    config.processPool = [[WKProcessPool alloc] init];
    
    WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, [self navBarBottom], ScreenWidth, ScreenHeight - [self navBarBottom]) configuration:config];
    //    webView.configuration = config;
    
    NSString * requster = [NSString stringWithFormat:@"%@",self.UrlString];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:requster]]];
    webView.scrollView.bounces = NO;
    webView.UIDelegate = self;
    webView.navigationDelegate = self;
    [self.view addSubview:webView];
    WYCLog(@"--------%@",requster);
    WYCLog(@"--------%@",self.UrlString);
    
}
#pragma mark --- WKNavigationDelegate
// 页面开始加载时调用
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
    [MBManager showLoading];
}
// 当内容开始返回时调用
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
    
}
// 页面加载完成之后调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    [MBManager hideAlert];
}
// 页面加载失败时调用
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation{
    [MBManager hideAlert];
}
- (void)CreateNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"资讯详情";
//    naviagtionBar.backgroundColor = BackViewColor;
    naviagtionBar.rightBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}


- (void)backClick{
    
    [self.navigationController popViewControllerAnimated: NO];
}
@end
